package com.yuji.aacar.net.interceptor;

import com.yuji.aacar.net.config.BlueLog;

import java.io.IOException;

import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * <li>Date: 2017/4/21 </li>
 * <li>Description: </li>
 */
public class MobileInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request original = chain.request();
        FormBody formBody = (FormBody) original.body();
        String header = formBody.size() > 1 ? formBody.value(1) : "";


        FormBody newBody = new FormBody.Builder().addEncoded("info", formBody.size() > 0 ? formBody.encodedValue(0) : "")
                .build();
        Request.Builder builder = original.newBuilder()
                .addHeader("Ttp", header)
                .post(newBody);

        Request request = builder.build();
        BlueLog.e("request_url", request.url() + "");
        return chain.proceed(request);
    }
}
